{% extends "layout.html" %}
{% macro display_bool_setting(setting_value) -%}
  {% if setting_value %}<span class="glyphicon glyphicon-ok"></span>{% else %}<span class="glyphicon glyphicon-remove"></span>{% endif %}
{%- endmacro %}
{% block body %}
<div class="container-fluid">
  <div class="row">
    <div class="col">
      <h2>{{_('Users')}}</h2>
      <table class="table table-striped" id="table_user">
        <tr>
            <th>{{_('Username')}}</th>
            <th>{{_('E-mail Address')}}</th>
            <th>{{_('Send to Kindle E-mail Address')}}</th>
            <th>{{_('Downloads')}}</th>
            <th class="hidden-xs">{{_('Admin')}}</th>
            <th class="hidden-xs">{{_('Download')}}</th>
            <th class="hidden-xs">{{_('View eBooks')}}</th>
            <th class="hidden-xs">{{_('Upload')}}</th>
            <th class="hidden-xs">{{_('Edit')}}</th>
        </tr>
        {% for user in allUser %}
          {% if not user.role_anonymous() or config.config_anonbrowse %}
          <tr>
            <td><a href="{{url_for('admin.edit_user', user_id=user.id)}}">{{user.nickname}}</a></td>
            <td>{{user.email}}</td>
            <td>{{user.kindle_mail}}</td>
            <td>{{user.downloads.count()}}</td>
            <td class="hidden-xs">{{ display_bool_setting(user.role_admin()) }}</td>
            <td class="hidden-xs">{{ display_bool_setting(user.role_download()) }}</td>
            <td class="hidden-xs">{{ display_bool_setting(user.role_viewer()) }}</td>
            <td class="hidden-xs">{{ display_bool_setting(user.role_upload()) }}</td>
            <td class="hidden-xs">{{ display_bool_setting(user.role_edit()) }}</td>
          </tr>
          {% endif %}
        {% endfor %}
      </table>
      <div class="btn btn-default" id="admin_new_user"><a href="{{url_for('admin.new_user')}}">{{_('Add New User')}}</a></div>
    </div>
  </div>

  <div class="row">
    <div class="col">
      <h2>{{_('E-mail Server Settings')}}</h2>
      <table class="table table-striped" id="table_email">
        <tr>
          <th>{{_('SMTP Hostname')}}</th>
          <th>{{_('SMTP Port')}}</th>
          <th>{{_('Encryption')}}</th>
          <th>{{_('SMTP Login')}}</th>
          <th class="hidden-xs">{{_('From E-mail')}}</th>
        </tr>
        <tr>
          <td>{{email.mail_server}}</td>
          <td>{{email.mail_port}}</td>
          <td>{% if email.mail_use_ssl %}<span class="glyphicon glyphicon-ok"></span>{% else %}<span class="glyphicon glyphicon-remove"></span>{% endif %}</td>
          <td>{{email.mail_login}}</td>
          <td class="hidden-xs">{{email.mail_from}}</td>
        </tr>
      </table>
      <div class="btn btn-default" id="admin_edit_email"><a href="{{url_for('admin.edit_mailsettings')}}">{{_('Change SMTP settings')}}</a></div>
    </div>
  </div>

  <div class="row">
    <div class="col">
      <h2>{{_('Configuration')}}</h2>
      <div class="col-xs-12 col-sm-6">
        <div class="row">
            <div class="col-xs-6 col-sm-6">{{_('Calibre Database Directory')}}</div>
            <div class="col-xs-6 col-sm-6">{{config.config_calibre_dir}}</div>
        </div>
        <div class="row">
            <div class="col-xs-6 col-sm-6">{{_('Log Level')}}</div>
            <div class="col-xs-6 col-sm-6">{{config.get_log_level()}}</div>
        </div>
        <div class="row">
            <div class="col-xs-6 col-sm-6">{{_('Port')}}</div>
            <div class="col-xs-6 col-sm-6">{{config.config_port}}</div>
        </div>
      </div>
      <div class="col-xs-12 col-sm-6">
        <div class="row">
            <div class="col-xs-6 col-sm-7">{{_('Books per Page')}}</div>
            <div class="col-xs-6 col-sm-5">{{config.config_books_per_page}}</div>
        </div>
        <div class="row">
            <div class="col-xs-6 col-sm-7">{{_('Uploads')}}</div>
            <div class="col-xs-6 col-sm-5">{{ display_bool_setting(config.config_uploading) }}</div>
        </div>
        <div class="row">
            <div class="col-xs-6 col-sm-7">{{_('Anonymous Browsing')}}</div>
            <div class="col-xs-6 col-sm-5">{{ display_bool_setting(config.config_anonbrowse) }}</div>
        </div>
        <div class="row">
            <div class="col-xs-6 col-sm-7">{{_('Public Registration')}}</div>
            <div class="col-xs-6 col-sm-5">{{ display_bool_setting(config.config_public_reg) }}</div>
        </div>
        <div class="row">
            <div class="col-xs-6 col-sm-7">{{_('Magic Link Remote Login')}}</div>
            <div class="col-xs-6 col-sm-5">{{ display_bool_setting(config.config_remote_login) }}</div>
        </div>
        <div class="row">
            <div class="col-xs-6 col-sm-7">{{_('Reverse Proxy Login')}}</div>
            <div class="col-xs-6 col-sm-5">{{ display_bool_setting(config.config_allow_reverse_proxy_header_login) }}</div>
        </div>
        {% if config.config_allow_reverse_proxy_header_login %}
        <div class="row">
            <div class="col-xs-6 col-sm-7">{{_('Reverse proxy header name')}}</div>
            <div class="col-xs-6 col-sm-5">{{ config.config_reverse_proxy_login_header_name }}</div>
        </div>
        {% endif %}
      </div>
      <div class="btn btn-default"><a id="basic_config" href="{{url_for('admin.configuration')}}">{{_('Edit Basic Configuration')}}</a></div>
      <div class="btn btn-default"><a id="view_config" href="{{url_for('admin.view_configuration')}}">{{_('Edit UI Configuration')}}</a></div>
    </div>
  </div>

  <div class="row">
    <div class="col">
      <h2>{{_('Administration')}}</h2>
      <div class="btn btn-default"><a id="logfile" href="{{url_for('admin.view_logfile')}}">{{_('View Logs')}}</a></div>
      <div class="btn btn-default" id="restart_database">{{_('Reconnect Calibre Database')}}</div>
      <div class="btn btn-default" id="admin_restart" data-toggle="modal" data-target="#RestartDialog">{{_('Restart')}}</div>
      <div class="btn btn-default" id="admin_stop" data-toggle="modal" data-target="#ShutdownDialog">{{_('Shutdown')}}</div>
    </div>
  </div>

  <div class="row">
    <div class="col">
      <h2>{{_('Update')}}</h2>
      <table class="table table-striped" id="update_table">
        <thead>
          <tr>
              <th class="col-xs-3">{{_('Version')}}</th>
              <th class="col-xl-8">{{_('Details')}}</th>
          </tr>
        </thead>
        <tbody>
          <tr id="current_version">
            <td>{{commit}} </td>
            <td><i>{{_('Current version')}}</i></td>
          </tr>
        </tbody>
      </table>

      <div class="hidden" id="update_error"> <span>{{update_error}}</span></div>
      <div class="btn btn-default" id="check_for_update">{{_('Check for Update')}}</div>
      <div class="btn btn-default hidden" id="perform_update" data-toggle="modal" data-target="#UpdateprogressDialog">{{_('Perform Update')}}</div>
    </div>
  </div>
</div>

<!-- Modal -->
<div id="RestartDialog" class="modal fade" role="dialog">
  <div class="modal-dialog modal-sm">
    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header bg-info"></div>
      <div class="modal-body text-center">
        <p>{{_('Are you sure you want to restart?')}}</p>
          <div id="spinner" class="spinner"  style="display:none;">
                <img id="img-spinner" src="{{ url_for('static', filename='css/libs/images/loading-icon.gif') }}"/>
          </div>
          <p></p>
        <button type="button" class="btn btn-default" id="restart" >{{_('OK')}}</button>
        <button type="button" class="btn btn-default" data-dismiss="modal">{{_('Cancel')}}</button>
      </div>
    </div>
  </div>
</div>
<div id="ShutdownDialog" class="modal fade" role="dialog">
  <div class="modal-dialog modal-sm">
    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header bg-info">
      </div>
      <div class="modal-body text-center">
        <p>{{_('Are you sure you want to shutdown?')}}</p>
        <button type="button" class="btn btn-default" id="shutdown" data-dismiss="modal">{{_('OK')}}</button>
        <button type="button" class="btn btn-default" data-dismiss="modal">{{_('Cancel')}}</button>
      </div>
    </div>
  </div>
</div>
<div id="UpdateprogressDialog" class="modal fade" role="dialog">
  <div class="modal-dialog modal-sm">
    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header bg-info text-center">
      <span>{{_('Updating, please do not reload this page')}}</span>
      </div>
      <div class="modal-body text-center">
          <div id="spinner2" class="spinner2"  style="display:none;">
                <img id="img-spinner2" src="{{ url_for('static', filename='css/libs/images/loading-icon.gif') }}"/>
          </div>
          <p></p>
         <div id="Updatecontent"></div>
          <p></p>
        <button type="button" class="btn btn-default hidden" id="updateFinished" data-dismiss="modal">{{_('OK')}}</button>
      </div>
    </div>
  </div>
</div>
{% endblock %}
